/*
 * CompositFeature.cpp
 *
 *  Created on: Feb 23, 2011
 *      Author: johang
 */

#include "CompositFeature.h"
#include "ContextLearnerUtils.h"
#include <stdio.h>

namespace findobject
{

  CompositFeature::CompositFeature(int featureFlags)
  {
    last_x = -1;
    last_y = -1;
    initAllFeatures();
    setFeatureTypes(featureFlags);
    dims = 0;
    for (int i = 0; i < m_usedFeatureTypes.size(); i++)
      {
        dims += m_featureBase[m_usedFeatureTypes[i]]->dims;
      }
  }

  void
  CompositFeature::initAllFeatures()
  {
    m_allFeatureTypes.push_back(NORMALSUM_FEATURE);
    m_featureBase[NORMALSUM_FEATURE] = new NormalSumFeature();

    m_allFeatureTypes.push_back(POSSUM_FEATURE);
    m_featureBase[POSSUM_FEATURE] = new PosSumFeature();

    m_allFeatureTypes.push_back(COLOURSUM_FEATURE);
    m_featureBase[COLOURSUM_FEATURE] = new ColourSumFeature();
  }

  CompositFeature::~CompositFeature()
  {
    // TODO Auto-generated destructor stub
  }

  /* --------------------------------------------------------------------------*/
  void
  CompositFeature::setFeatureTypes(int featureFlags)
  {
    while (featureFlags != 0)
      {
        for (int i = 0; i < m_allFeatureTypes.size(); i++)
          {
            if ((featureFlags & m_allFeatureTypes[i]) == m_allFeatureTypes[i])
              {
                m_usedFeatureTypes.push_back(m_allFeatureTypes[i]);
                featureFlags -= m_allFeatureTypes[i];
              }
          }
      }
  }

  void
  CompositFeature::getResponse(float * output, Point ** points, int x, int y, int * divi)
  {
    last_x = x;
    last_y = y;
    int d = 0;
    for (int i = 0; i < m_usedFeatureTypes.size(); i++)
      {
        int featureEnumVal = m_usedFeatureTypes[i];
        m_featureBase[featureEnumVal]->getResponse(&(output[d]), points, x, y, divi);
        d += m_featureBase[featureEnumVal][i].dims;
      }
  }
}
;
